package mybatis.generator.plugin.plugins;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.internal.DefaultCommentGenerator;
import org.mybatis.generator.internal.util.StringUtility;

/**
 * @Description: 自定义 注释
 * @Author: wanghanrui
 */
public class CustomComment extends DefaultCommentGenerator {

    /**
     * 类注释
     * connection 必须配置useInformationSchema，插件才能获取到表的注释
     */
    @Override
    public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        String remarks = introspectedTable.getRemarks();
        if ( StringUtility.stringHasValue(remarks)){
            topLevelClass.addJavaDocLine("/** ");
            topLevelClass.addJavaDocLine(" * @Description: " + remarks);
            topLevelClass.addJavaDocLine(" * @WARNING This class was generated by MyBatis Generator, do not modify.");
            topLevelClass.addJavaDocLine(" */");
        }
    }

    /**
     * 属性注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        if ( StringUtility.stringHasValue(remarks)){
            field.addJavaDocLine("/** "+ remarks+ " */");
        }
    }


}
